package com.design.classroommanagement.api.dao

import com.design.classroommanagement.api.Role
import com.design.classroommanagement.api.User
import com.design.classroommanagement.api.toMap
import java.sql.ResultSet

class TeacherDao : BaseDao<User> {
    override fun getData(rs: ResultSet): User {
        val user = User()
        user.account = rs.getDecodeObject("account")?.toString()
        user.name = rs.getDecodeObject("name")?.toString()
        user.password = rs.getDecodeObject("password")?.toString()
        user.id = rs.getDecodeObject("id")?.toString()
        user.telephone = rs.getDecodeObject("telephone")?.toString()
        user.sex = rs.getDecodeObject("sex")?.toString()
        user.age = rs.getDecodeObject("age")?.toString()
        user.college = rs.getDecodeObject("college")?.toString()
        user.role = Role.teacher

        return user
    }

    override fun getTableName(): String {
        return "teacher"
    }

    override fun getDbMap(t: User): HashMap<String, Any> {
        return t.toMap().apply {
            remove("id")
            remove("role")
        }
    }
}